import axios from "axios";
import { showToast } from "vant";

//axios工具封装
const http = axios.create({
    baseURL:'https://meikou-api.itheima.net',
    timeout:5000
})
//请求拦截器
http.interceptors.request.use((config)=>{
    try{
        const user = mk.queryUser()
        if(user.token){
            config.headers.Authorization =`Bearer ${user.token}`
        }
    }catch(e){
        showToast({message:'美寇SDK异常'})
    }

    return config
},(err)=>{
    return Promise.reject(err)
})
//响应拦截器
http.interceptors.response.use((res)=>{
    return res
},(err)=>{
    return Promise.reject(err)
})

export {http}